package com.huizhonglm.diap.core.utils;

import android.content.Context;
import android.os.Environment;
import android.os.StatFs;

import com.bruce.common.utils.FileUtil;
import com.huizhonglm.diap.DiapApplication;

import java.io.File;

/**
 * 描述当前类的作用
 *
 * @author LiXiaoLong
 * @version 1.0
 * @since 2016-03-03 10:03
 */
public class SdcardUtil {

    /**
     * sd卡挂载且可用
     *
     * @return SD卡是否可用（true：可用，false：不可用）
     */
    public static boolean isMounted() {
        return Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
    }

    /**
     * sd卡可用空间
     *
     * @return sd卡可用空间
     */
    public static long getAvailaleSize() {
        File path = Environment.getExternalStorageDirectory(); // 取得sdcard文件路径
        StatFs stat = new StatFs(path.getPath());
        long blockSize = stat.getBlockSize();
        long availableBlocks = stat.getAvailableBlocks();
        return availableBlocks * blockSize;
    }

    /**
     * 获取应用缓存目录
     *
     * @return /sdCard/Android/data/com.huizhonglm.diap/
     */
    public static String getFilePath() {
        Context con = DiapApplication.getInstance().getContext();
        final String cacheDir = "/Android/data/" + con.getPackageName() + "/";
        String path = Environment.getExternalStorageDirectory().getPath() + cacheDir;
        FileUtil.createDir(path);
        return path;
    }

    /**
     * 获取临时文件夹
     *
     * @return /sdCard/Android/data/com.huizhonglm.diap/temp/
     */
    public static String getTempPath() {
        String path = getFilePath() + "temp/";
        FileUtil.createDir(path);
        return path;
    }

    /**
     * 获取相册路径
     *
     * @return /sdCard/DCIM/Camera/
     */
    public static String getDCIMPath() {
        final String cacheDir = "/DCIM/Camera/";
        return Environment.getExternalStorageDirectory().getPath() + cacheDir;
    }

    /**
     * 获取应用缓存目录
     *
     * @return /sdCard/Android/data/com.huizhonglm.diap/cache/
     */
    public static String getCachePath() {
        String path = getFilePath() + "cache/";
        FileUtil.createDir(path);
        return path;
    }
}
